package ActualRefactoring;

public class Account2 { 
    float principal; 
    float rate; 
    int daysActive; 
    int accountType; 

    public static final int  STANDARD = 0; 
    public static final int  BUDGET = 1; 
    public static final int  PREMIUM = 2; 
    public static final int  PREMIUM_PLUS = 3; 
 
    public static final double  MAGIC_NO = 0.125; 

 float calculateFee(Account2 accounts[]) { 
    float totalFee = 0; 
    Account2 account; 
    for (int i = 0; i < accounts.length; i++) { 
        account = accounts[i]; 
//TODO 1 Adding method isPremium to check the whether an account is premium
        if ( isPremium(account) ) { 
//TODO 2 Extract the interest calculation and create a method call named as "interestEarned"
//TODO 3 Replace Magic Number with a static constant
            totalFee += interestEarned(account);
        } 
    } 
    return totalFee; 
  }
 
 
 boolean isPremium(Account2 account){
	 if ( account.accountType == Account2.PREMIUM ||  
	            account.accountType == Account2.PREMIUM_PLUS ) return true;
	 else return false;
 }
 
 
 double interestEarned(Account2 account){
	 double interest = MAGIC_NO * ( account.principal  
             * Math.exp( account.rate * (account.daysActive/365.25) ) 
             - account.principal );
	return interest; 
 }
 
 
 
 
 
 
}